import axios from '@/functions/request';

// 导入BPMNJS 文件
import BpmnModel from "bpmn-js/lib/Modeler";

// 语言翻译
import CustomTranslate from "@/assets/bpmn/customTranslate/customTranslate";
// 引入右侧属性栏的框
import BpmnPanel from "bpmn-js-properties-panel";
// 导入 camunda
import CamundaModel from "camunda-bpmn-moddle/resources/camunda";
// camunda 属性
import CamundaProperties from "bpmn-js-properties-panel/lib/provider/camunda";

// 创建默认含有属性模板的Model
function createBpmnModel(canvas,panelProp) {
  const TranslateModel = {
    translate: ["value", CustomTranslate]
  };
  return new BpmnModel({
    container: canvas,
    propertiesPanel: {
        parent: panelProp
    },
    additionalModules: [BpmnPanel, CamundaProperties, TranslateModel],
    moddleExtensions: {
      camunda: CamundaModel
    }
  });
}

// 创建原生Model
function createOriBpmnModel(canvas) {
  return new BpmnModel({
    container: canvas,
  });
}

function downloadBpmn(name,data){
  let encodedData = encodeURIComponent(data);
  var aEle = document.createElement("a");
  aEle.download = name;
  aEle.href = 'data:application/bpmn20-xml;charset=UTF-8,' + encodedData;
  aEle.click();
}

export {
    createBpmnModel,
    createOriBpmnModel,
    downloadBpmn
}